﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using XQ.SP.Model;

namespace XQ.SP.BllServices{
	 	//BaseCity
		public partial class BaseCityBLL : BaseBll
	{
   		     
		private readonly XQ.SP.DalServices.BaseCityDal dal=new XQ.SP.DalServices.BaseCityDal();
		public BaseCityBLL()
		{}
		
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool ExistsWhere(string whereSql)
		{
			return dal.ExistsWhere(whereSql);
		}
		
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int BaseCityID)
		{
			return dal.Exists(BaseCityID);
		}

		
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(XQ.SP.Model.BaseCityItem model)
		{
			return dal.Add(model);	
		}

		/// <summary>
		/// 批量增加数据
		/// </summary>
		public bool  AddList(List<XQ.SP.Model.BaseCityItem> models)
		{
            int rows=dal.AddList(models);
            if (rows > 0)
                return true;
            else
                return false;
		}


		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(XQ.SP.Model.BaseCityItem model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 批量更新数据
		/// </summary>
		public int UpdateList(List<XQ.SP.Model.BaseCityItem> models)
		{
			return dal.UpdateList(models);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int BaseCityID)
		{
			
			return dal.Delete(BaseCityID);
		}
				/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string BaseCityIDlist )
		{
			return dal.DeleteList(BaseCityIDlist );
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XQ.SP.Model.BaseCityItem GetModel(int BaseCityID)
		{
			
			return dal.GetModel(BaseCityID);
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XQ.SP.Model.BaseCityItem GetModelWhereStr(string whereSql)
		{
			
			return dal.GetModelWhereStr(whereSql);
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere="")
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<XQ.SP.Model.BaseCityItem> GetModelList(string strWhere="")
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		
        /// <summary>
        /// 获得新增的数据
        /// </summary>
        public List<XQ.SP.Model.BaseCityItem> GetModelListNew(string datetimeStr)
        {
            DataSet ds = dal.GetList(" Created>='"+datetimeStr+"' ");
            return DataTableToList(ds.Tables[0]);
        }
        
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<XQ.SP.Model.BaseCityItem> DataTableToList(DataTable dt)
		{
			List<XQ.SP.Model.BaseCityItem> modelList = new List<XQ.SP.Model.BaseCityItem>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				XQ.SP.Model.BaseCityItem model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new XQ.SP.Model.BaseCityItem();					
													if(dt.Rows[n]["BaseCityID"].ToString()!="")
				{
					model.BaseCityID=int.Parse(dt.Rows[n]["BaseCityID"].ToString());
				}
																																if(dt.Rows[n]["BaseProvinceID"].ToString()!="")
				{
					model.BaseProvinceID=int.Parse(dt.Rows[n]["BaseProvinceID"].ToString());
				}
																																				model.BaseCityName= dt.Rows[n]["BaseCityName"].ToString();
																												if(dt.Rows[n]["SortNumber"].ToString()!="")
				{
					model.SortNumber=int.Parse(dt.Rows[n]["SortNumber"].ToString());
				}
																																				model.Url= dt.Rows[n]["Url"].ToString();
																																model.Description= dt.Rows[n]["Description"].ToString();
																						
				
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
		

   
		/// <summary>
		/// Model的属性对应赋值
		/// </summary>
		public void ModelCopy(XQ.SP.Model.BaseCityItem modelOld,XQ.SP.Model.BaseCityItem modelNew)
		{
			            
            modelNew.BaseCityID = modelOld.BaseCityID;
                        
            modelNew.BaseProvinceID = modelOld.BaseProvinceID;
                        
            modelNew.BaseCityName = modelOld.BaseCityName;
                        
            modelNew.SortNumber = modelOld.SortNumber;
                        
            modelNew.Url = modelOld.Url;
                        
            modelNew.Description = modelOld.Description;
            		}
#endregion
   
	}
}